<?php

namespace App\Http\Controllers\Backend;

use LaravelAnalytics;

class AnalyticController extends BaseController {

    public function site()
    {
        return view('backend.analytic.site');
    }

    public function visitorStatistics()
    {
        // $analyticsData = LaravelAnalytics::getVisitorsAndPageViews(7);
        $visitors = LaravelAnalytics::getVisitorsAndPageViews(13);

        $data = [];
        foreach($visitors as $visitor) {

            $data[] = [$visitor['date']->toDateString(), $visitor['visitors']];
        }

        // $data = [];
        // foreach($visitors as $visitor) {
        //     $data[] = [$visitor->date->toDateString(), $visitor->pageViews],
        // }

        return $data;
    }

    public function pvStatistics()
    {
        $visitors = LaravelAnalytics::getVisitorsAndPageViews(13);

        $data = [];
        foreach($visitors as $visitor) {

            $data[] = [$visitor['date']->toDateString(), $visitor['pageViews']];
        }

        return $data;
    }

    public function key()
    {
        return view('backend.analytic.key');
    }

    public function project()
    {
        return view('backend.analytic.project');
    }

    public function exception()
    {
        return view('backend.analytic.exception');
    }
}